﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;

namespace Yonkly.Utility
{
    public static class ImageHelper
    {
        public static byte[] ToByteArray(this System.Drawing.Image imageIn, System.Drawing.Imaging.ImageFormat imgFormat)
        {
            MemoryStream ms = null;
            try
            {
                ms = new MemoryStream();
                imageIn.Save(ms, imgFormat); //System.Drawing.Imaging.ImageFormat.Gif
                return ms.ToArray();
            }
            finally
            {
                if (ms != null) ms.Dispose();
            }
        }

        public static Image byteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }
    }
}
